package com.bosssoft.quickstart.utilsTest;

import com.bosssoft.quickstart.utils.MyBeanUtil;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.beans.BeanUtils;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
@SpringBootTest
class MyBeanUtilTest {

    @Mock
    private MyBeanUtil.IBeanCopyCallback<Object, Object> callback;

    @BeforeEach
    void setUp() {
        MockitoAnnotations.initMocks(this);
    }

    @Test
    void testCopyList() {
        List<String> sourceList = new ArrayList<>(Arrays.asList("item1", "item2"));
        List<String> targetList = MyBeanUtil.copyList(sourceList, String::new, callback);

        assertNotNull(targetList);
        assertEquals(sourceList.size(), targetList.size());
        verify(callback, times(sourceList.size())).execute(any(), any());
    }

    @Test
    void testCopyListWithNullSource() {
        Exception exception = assertThrows(IllegalArgumentException.class, () -> 
            MyBeanUtil.copyList(null, String::new, callback)
        );
        assertEquals("源头列表不能为空", exception.getMessage());
    }

    @Test
    void testCopyProperties() {
        String source = "testString";
        String target = MyBeanUtil.copyProperties(source, String::new);

        assertNotNull(target);
        assertEquals(source, target);
    }

    @Test
    void testCopyPropertiesWithNullSource() {
        Exception exception = assertThrows(IllegalArgumentException.class, () ->
            MyBeanUtil.copyProperties(null, String::new)
        );
        assertEquals("源参数不可以为空", exception.getMessage());
    }
}
